package com.scst.controller.user;

import com.scst.dto.OrdersPaymentDTO;
import com.scst.dto.OrdersSubmitDTO;
import com.scst.result.Result;
import com.scst.service.OrderService;
import com.scst.vo.OrderPaymentVO;
import com.scst.vo.OrderSubmitVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    OrderService orderService;
    @PostMapping ("/submit")
    @ApiOperation("用户订单")
    public Result<OrderSubmitVO> submit(OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO=orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
    @PostMapping ("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable("id") Long id) throws Exception {
        orderService.userCancelById(id);
        return Result.success();
    }
    @GetMapping("/remider/{id}")
    @ApiOperation("客户催单")
    public Result reminder(@PathVariable ("id") Long id) {
        orderService .reminder(id);
        return Result.success();
    }
}
